<script setup lang="ts">
import { tableConfig } from './table-config';
import { doGetCraftList } from '@/api/demand/order/index';
import { generateNameToLevel } from '@/config/constant';
import type { OrderListRecord, ProcessRecord } from '@/api/demand/order/model/type';

const dialogVisible = ref(false);
const materialCode = ref('');
const { getMaxHeight, handleFullscreen } = useModal();

/**
 * @: 打开弹框
 */
const open = (row: OrderListRecord) => {
    materialCode.value = row.itemCode;
    dialogVisible.value = true;
};

/**
 * @: 处理序号
 * @param {*} data
 * @return {*}
 */
const handleTableData = ({ records }: { records: ProcessRecord[] }) => {
    let index = 1;
    return records.map(item => {
        let key: string;
        const obj: any = {};
        for (key in item) {
            obj[key] = item[key] ?? '';
        }
        if (item.id) {
            return {
                index: index++,
                ...obj
            };
        }
        return obj;
    });
};

defineExpose({
    open
});
</script>

<template>
    <q-modal
        v-model:visible="dialogVisible"
        title="工艺查询"
        :fullscreen="true"
        :footer="false"
        width="1100px"
        @fullscreen="handleFullscreen"
    >
        <base-table
            :id="generateNameToLevel('1')"
            :table-config="tableConfig"
            :get-data-fn="doGetCraftList"
            :handle-table-data="handleTableData"
            :added-params="{ materialCode }"
            :modal-mode="true"
            :max-height="getMaxHeight"
            :un-action="true"
            :show-setting="false"
        >
            <template #index="{ item }">
                <el-table-column :label="item.columnProps?.label" width="65" align="center">
                    <template #default="{ row }"> {{ row.index }} </template>
                </el-table-column>
            </template>
        </base-table>
    </q-modal>
</template>

<style scoped lang="scss"></style>
